<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_安全库存设置</title>
	<script type="text/javascript">
	
        $(function() {
		    $("#queryForm").validate(); 
        });
        
        function setting(id){
          
          var areagroupCode_id="#areagroupCode_"+id;
          var customerCode_id="#customerCode_"+id;
          var sku_id="#sku_"+id;
          var safeNum_id="#safeNum_"+id;
          var iswarning_id="#iswarning_"+id;
          
          var areagroupCode=$(areagroupCode_id).val();
          var customerCode=$(customerCode_id).val();
          var sku=$(sku_id).html();
          var safeNum=$(safeNum_id).val();
          var iswarning=$(iswarning_id).val();
          
          //验证
          if(isNaN(safeNum)){
             message("请设置有效的安全库存！");
             $(safeNum_id).focus();
             $(safeNum_id).select();
             return false;
          }
          
           //验证
          if(safeNum==''){
             message("请设置有效的安全库存！");
             $(safeNum_id).focus();
             $(safeNum_id).select();
             return false;
          }
         
          $.ajax({
			type : 'post',
			url : '${ctx}/stockSafe/ajaxSetting',
			data : {
				areagroupCode : areagroupCode,
				customerCode : customerCode,
				sku : sku,
				safeNum:safeNum,
				iswarning:iswarning
			},
			dataType : 'json',
			success : function(data) {
				if (data == true) {
					message("设置成功！");
				} else {
					alert("网络繁忙，请稍后重试...");
				}
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		  });
          
        }
        
        
        function message(message){
           $("#message").html(message);
           window.setTimeout("disappear()",1500); 
        }
        
        function disappear(){
          $("#message").html('');
        }
        
    </script>
</head>

<body>
	
    <div id="message" class="alert alert-success" style="height: 20px;"></div>
	
	<div style="height: 10px;"></div>
	
	<div class="row">
		<div class="span12" style="margin-left: 20px;">
			<form class="form-search" id="queryForm" action="${ctx}/stockSafe" method="post">
				<label style="margin-left:10px;">仓库网点：</label> 
				<select  name="_areagroupCode"  id="_areagroupCode" value="${param._areagroupCode}"  class="input-medium">
					<option value=""></option>
					<c:forEach items="${areagroupList}" var="areagroup">
						<option value="${areagroup.groupCode}"
						<c:if test="${param._areagroupCode eq areagroup.groupCode}">selected=selected</c:if>
						>${areagroup.groupName}</option>
					</c:forEach>
				</select>
				
				<label style="margin-left:10px;">商家：</label> 
				<select  name="_customerCode"  id="_customerCode" value="${param._customerCode}" class="input-medium">
					<option value=""></option>
					<c:forEach items="${customersList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
				
				<label style="margin-left:10px;">SKU编码：</label> 
				<input type="text" name="_sku" id="_sku" class="input-medium" value="${param._sku}" style="margin-left: -10px;">
				
			    <button type="submit" class="btn" style="margin-left: 10px;">搜索</button>
		    </form>
	    </div>
	</div>
	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 150px;">仓库网点</th>
		    <th style="width: 150px;">商家名称</th>
		    <th style="width: 150px;">SKU编码</th>
		    <th style="width: 150px;">安全库存</th>
		    <th style="width: 150px;">是否预警</th>
		    <th style="width: 150px;">当前库存</th>
		    <th>操作</th>
		</tr></thead>
		
		<c:forEach items="${settingList}" var="setting">
			<tr>
			   <td id="areagroupName_${setting.field8}" >${setting.field1}</td>
			   <td id="customerName_${setting.field8}">${setting.field2}</td>
			   <td id="sku_${setting.field8}">${setting.field3}</td>
			   <td>
			     <input type="hidden" id="areagroupCode_${setting.field8}" value="${setting.field9}"/>
			     <input type="hidden" id="customerCode_${setting.field8}" value="${setting.field10}"/>
			     <input  type="text" style="width: 130px;" value="${setting.field4}" id="safeNum_${setting.field8}"/>
			   </td>
			   <td>
			      <select style="width: 130px;" id="iswarning_${setting.field8}">
			        <option value="1" <c:if test="${setting.field5 eq '1'}">selected=selected</c:if> >是</option>
			        <option value="0" <c:if test="${setting.field5 ne '1'}">selected=selected</c:if> >否</option>
			      </select>
			   </td>
			   <td>${setting.field6}</td>
			   <td>
			     <a href="#detail" data-toggle="modal" class="btn btn-info" id="btn_${setting.field8}" onclick="setting('${setting.field8}');">设置</a>
			   </td>
			</tr>
		</c:forEach>
		
	</table>
	
	
</body>
</html>
